package com.base.controller;

import com.base.po.tbk.TbkGoodContent;
import com.base.service.LogsService;
import com.base.service.TbkGoodContentService;
import com.base.utils.Produce;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

/**
 * 添加好货专场服务端
 */
@Controller
@RequestMapping("/admin")
public class add_GoodContent{

	@Autowired
	private LogsService logsService;// log日志
	@Autowired
	private TbkGoodContentService tbkGoodContentService;

	@RequestMapping("/addGoodContent")
	public ModelAndView addGoodContent(HttpServletRequest request) throws Exception {
		ModelAndView modelAndView = new ModelAndView();

		modelAndView.setViewName("jsp/add_GoodContent");
		return modelAndView;
	}

	@RequestMapping(value = "/toAddGoodContent", method = RequestMethod.POST)
	public @ResponseBody int toAddGoodContent(HttpServletRequest request, TbkGoodContent tbkGoodContent){
		String userid = (String) request.getSession().getAttribute("adminUserId"); // 登录的用户ID
		if (userid == null) return -1; // 未登录

		tbkGoodContent.setId(Produce.getUUID());
		tbkGoodContent.setParentid(userid); // 代理商ID
		tbkGoodContent.setCreatetime(Produce.getNowDate()); // 创建时间
		tbkGoodContent.setDatastatus(1); // 状态可用
		return tbkGoodContentService.insertSelective(tbkGoodContent); // 添加
	}
}
